﻿namespace MicroCloud.Audit.Entities
{
    /// <summary>
    /// 实体类：审计实体信息
    /// </summary>
    [MapFrom(typeof(AuditEntityEntry))]
    [Description("审计实体信息")]
    [EventEntityIgnore]
    [Table(nameof(AuditEntity), Schema = TableSchemaConstants.Audit)]
    [ValueGenerate(ValueGenerateRule.Never, ValueGenerateMode.Snowflake)]
    public class AuditEntity : EntityBase<long>
    {
        #region 构造函数
        /// <summary>
        /// 初始化一个实体类：审计实体信息 <see cref="AuditEntityEntry"/> 的新实例
        /// </summary>
        public AuditEntity()
            : this(null, null, OperateType.Query)
        { }

        /// <summary>
        /// 初始化一个实体类：审计实体信息 <see cref="AuditEntityEntry"/> 的新实例
        /// </summary>
        /// <param name="name"></param>
        /// <param name="typeName"></param>
        /// <param name="operateType"></param>
        public AuditEntity(string name, string typeName, OperateType operateType)
        {
            Name = name;
            TypeName = typeName;
            OperateType = operateType;
        }

        #endregion

        #region 所属审计操作编号
        /// <summary>
        /// 获取或设置 所属审计操作编号
        /// </summary>
        [Column("OperationId")]
        [DisplayName("所属审计操作编号")]
        //[ForeignKey("Operation")]
        public long OperationId { get; set; }

        #endregion

        #region 实体名称
        private string _Name = "";
        /// <summary>
        /// 获取或设置 实体名称
        /// </summary>
        [Column("Name")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("实体名称")]
        public string Name { get { return _Name; } set { _Name = value.ReplaceNull(); } }
        #endregion

        #region 类型名称
        private string _TypeName = "";
        /// <summary>
        /// 获取或设置 类型名称
        /// </summary>
        [Column("TypeName")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.General)]
        [DisplayName("类型名称")]
        public string TypeName { get { return _TypeName; } set { _TypeName = value.ReplaceNull(); } }

        #endregion

        #region 数据编号
        private string _EntityKey = "";
        /// <summary>
        /// 获取或设置 数据编号
        /// </summary>
        [Column("EntityKey")]
        [Required, DefaultValue("")]
        [StringSize(StringSizeType.Name)]
        [DisplayName("数据编号")]
        public string EntityKey { get { return _EntityKey; } set { _EntityKey = value.ReplaceNull(); } }

        #endregion

        #region 操作类型
        /// <summary>
        /// 获取或设置 操作类型
        /// </summary>
        [Column("OperateType")]
        [DisplayName("操作类型")]
        public OperateType OperateType { get; set; }

        #endregion

        #region 导航属性        
        /// <summary>
        /// 获取或设置 所属审计操作
        /// </summary>
        [JsonIgnore]
        public virtual AuditOperation Operation { get; set; }

        /// <summary>
        /// 获取或设置 审计实体属性集合
        /// </summary>
        public virtual ICollection<AuditProperty> Properties { get; set; } = new List<AuditProperty>();

        #endregion

    }
}
